import { queryWxUsersList } from '@/services/vip';
import { message } from 'antd';
import { addUser } from '@/services/user';
import { initShop } from '@/services/shop';
export default {
  namespace: 'vip',

  state: {
    wxUserMap: {
      list: [],
      pagination: {},
    },
    userInfo: {},
  },
  effects: {
    *fetchWxUser({ payload }, { call, put }) {
      const response = yield call(queryWxUsersList, payload);
      yield put({
        type: 'save',
        payload: {
          list: response.data.data,
          pagination: {
            total: response.data.total,
            pageSize: 10,
            current: parseInt(response.data.currentPage, 10) || 1,
          },
        },
      });
    },
    *fetchAddUserAccount({ payload, callback }, { call, put }) {
      const response = yield call(addUser, payload);
      console.log(response.status);
      if (response.status === 'success') {
        if (callback) callback();
      }
    },
    *fetchAddUserAccount({ payload, callback }, { call, put }) {
      const response = yield call(addUser, payload);
      if (response.status === 'success') {
        if (callback) callback();
      } else {
        message.error(response.message);
      }
    },
    *fetchInitShop({ payload, callback }, { call, put }) {
      const response = yield call(initShop, payload);
      console.log(response.status);
      if (response.status === 'success') {
        if (callback) callback();
      }
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        wxUserMap: action.payload,
      };
    },
  },
};
